package com.gxa.controller;

import com.gxa.common.R;
import com.gxa.common.ResponseData;
import com.gxa.pojo.*;
import com.gxa.service.DeptService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@Api(value = "部门数据test",tags = "部门数据接口API")
@RequestMapping(value = "/dept",method = RequestMethod.GET  )
public class DeptController {
    @Autowired
    private DeptService deptService;
    // 查询部门信息
    @RequestMapping(value = "/queryDeptList",method = RequestMethod.GET)
    @ApiOperation(value = "部门查询接口",notes = "传递当前页码数和每页显示记录数",httpMethod = "GET",response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",required = true,dataType = "String",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    @ResponseBody
    public ResponseData queryDeptList(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize") Integer pageSize){

        return deptService.queryDeptList(currentPage,pageSize);
    }
     // 添加部门
    @RequestMapping(value = "/addDept",method = RequestMethod.POST)
    @ApiOperation(value = "添加部门接口",notes = "添加部门信息",httpMethod = "POST", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData addDept(@RequestBody @ApiParam(name = "dept",value = "添加部门信息",required = true) Dept dept){

        return deptService.addDept(dept);
    }
     //修改部门信息
    @RequestMapping(value = "/updateDept",method = RequestMethod.POST)
    @ApiOperation(value = "修改部门接口",notes = "修改部门信息",httpMethod = "POST", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData updateDept(@RequestBody @ApiParam(name = "dept",value = "修改部门信息",required = true) Dept dept){

        return deptService.updateDept(dept);
    }
    //回显编辑部门信息
    @RequestMapping(value = "/editDept",method = RequestMethod.GET)
    @ApiOperation(value = "回显编辑部门信息接口",notes = "回显编辑部门信息",httpMethod = "GET", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData editDept(@RequestBody @ApiParam(name = "dept",value = "回显编辑部门信息",required = true) Integer dept_id){

        return deptService.editDept(dept_id);
    }
    // 删除
     @RequestMapping(value = "/delDept",method = RequestMethod.POST)
     @ApiOperation(value = "删除部门信息接口",notes = "删除部门信息",httpMethod = "POST", response = ResponseData.class)
     @ApiResponses({
             @ApiResponse(code=200,message="请求成功"),
             @ApiResponse(code=404,message="找不到页面"),
             @ApiResponse(code=500,message="后台服务错误")
     })
     @ResponseBody
     public ResponseData delDept(@RequestBody @ApiParam(name = "dept",value = "删除部门信息",required = true) Dept dept){
         int dept_id = dept.getDept_id();
         int dept_level = dept.getDept_level();
         return deptService.delDept(dept_id,dept_level);
     }
     //关键字查找
    @RequestMapping(value = "/searchDeptList",method = RequestMethod.GET)
    @ApiOperation(value = "部门搜索接口",notes = "传递当前页码数和每页显示记录数",httpMethod = "GET",response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",required = true,dataType = "String",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    @ResponseBody
    public ResponseData searchDeptList(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize") Integer pageSize,@RequestParam("keyword")String keyword){

        return deptService.searchDeptList(currentPage,pageSize,keyword);
    }
     //点击查询员工
     @RequestMapping(value = "/queryEmp",method = RequestMethod.GET)
     @ApiOperation(value = "点击查询部门员工接口",notes = "部门员工信息",httpMethod = "GET",response = ResponseData.class)
     @ApiResponses({
             @ApiResponse(code = 200,message = "请求成功"),
             @ApiResponse(code = 404,message = "找不到页面"),
             @ApiResponse(code = 500,message = "后台服务错误")
     })
     @ResponseBody
     public ResponseData queryEmpList(@RequestParam("dept_name")String dept_name){

         return deptService.queryEmpList(dept_name);
     }
    // 查询部门组织架构
    @RequestMapping(value = "/queryDept",method = RequestMethod.GET)
    @ApiOperation(value = "查询部门组织架构接口",notes = "查询部门组织架构信息",httpMethod = "GET",response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    @ResponseBody
    public ResponseData queryDept(){

        return deptService.queryDept();
    }
    // 查询一级部门
    @RequestMapping(value = "/queryDept1List",method = RequestMethod.GET)
    @ApiOperation(value = "查询一级部门接口",notes = "查询一级部门信息",httpMethod = "GET",response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    @ResponseBody
    public ResponseData queryDept1List(){

        return deptService.queryDept1List();
    }
    // 查询二级部门
    @RequestMapping(value = "/queryDept2List",method = RequestMethod.GET)
    @ApiOperation(value = "查询二级部门接口",notes = "查询二级部门信息",httpMethod = "GET",response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    @ResponseBody
    public ResponseData queryDept2List(){

        return deptService.queryDept2List();
    }
    // 查询三级部门
    @RequestMapping(value = "/queryDept3List",method = RequestMethod.GET)
    @ApiOperation(value = "查询三级部门接口",notes = "查询三级部门信息",httpMethod = "GET",response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    @ResponseBody
    public ResponseData queryDept3List(){

        return deptService.queryDept3List();
    }


}
